import { defineStore } from 'pinia'
import { computed, ref } from 'vue'

// 文件模块
export const useFileStore = defineStore(
  'big-file',
  () => {
    const userFile = ref({
      parentId: null,
      breadCrumbs: []
    })

    const parentId = computed(() => userFile.value.parentId)
    const breadCrumbs = computed(() => userFile.value.breadCrumbs)

    const setParentId = data => {
      userFile.value.parentId = data
    }
    const setBreadCrumbs = data => {
      userFile.value.breadCrumbs = data
    }

    const clearUserFile = () => {
      userFile.value = {
        parentId: null
      }
    }

    const clearBreadCrumbs = () => {
      userFile.value.breadCrumbs = []
    }

    const addItem = data => {
      userFile.value.breadCrumbs.push(data)
    }

    const clear = () => {
      userFile.value = {
        parentId: null,
        breadCrumbs: []
      }
    }

    return {
      userFile,
      parentId,
      breadCrumbs,
      setParentId,
      setBreadCrumbs,
      clearUserFile,
      addItem,
      clear,
      clearBreadCrumbs
    }
  },
  {
    // 持久化
    persist: true
  }
)
